import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.List;

import org.junit.Test;
import org.springframework.context.ApplicationContext;

import com.baohua.dao.StaffDao;
import com.baohua.model.Staff;
import com.baohua.util.ExcelUtil;



public class CaseTest {

	ApplicationContext ctx;
//	@Before
//	public void beforeTest() {
//		String[] config = new String[] {"/WebContent/WEB-INF/spring-Beans.xml",
//        "/WebContent/WEB-INF/spring-jdbc.xml"};
//		ctx = new FileSystemXmlApplicationContext(config);
//	}
	
	@Test
	public void exportExcel() throws IllegalArgumentException, IOException, IllegalAccessException {
		OutputStream output = new FileOutputStream("D:/員工列表.xls");
		ExcelUtil<Staff> excelUtil = new ExcelUtil<Staff>(Staff.class);
		StaffDao staffDao = (StaffDao)ctx.getBean("staffDao");
		List<Staff> list = staffDao.queryStaff("from Staff", 1, 10);
		excelUtil.exportExcel(list, "員工列表", false, output);
	}
	
	@Test
	public void queryByStaffNos() {
		StaffDao staffDao = (StaffDao)ctx.getBean("staffDao");
		String[] staffNOs = {"admin", "eee", "fee", "ffff"};
		List<Staff> list = staffDao.queryByStaffNOs(staffNOs);
		System.out.println(list.size());
		for(Staff staff : list) {
			System.out.println(staff.getAddress());
		}
	}
	
	@Test
	public void queryByStaffNos1() {
		StaffDao staffDao = (StaffDao)ctx.getBean("staffDao");
		List<Staff> list = staffDao.queryStaff("from Staff", 1, 10);
		System.out.println(list.size());
		for(Staff staff : list) {
			System.out.println(staff.getAddress());
		}
	}
	
	@Test
	public void getTClass() {
	}
	
	
}
